﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.SilverlightMediaFramework.Data.Settings;
using Microsoft.SilverlightMediaFramework.Data;
using Microsoft.SilverlightMediaFramework;

namespace SMF.HowTo.Sample
{
    public partial class MainPage : UserControl
    {
        private CustomSettings _settings;

        public MainPage()
        {
            InitializeComponent();

            Source settingsSource = new Source
            {
                Name = "SettingsSource",
                Interval = TimeSpan.FromSeconds(10),
                Url = new Uri("http://localhost:16083/datasources/settings.xml")
            };

            _settings = new CustomSettings
            {
                SettingsSource = settingsSource
            };

            SettingsClient settingsClient = new SettingsClient(_settings, "SettingsSource");
            settingsClient.RequestCompleted += new EventHandler<SimpleEventArgs<SettingsBase>>(settingsClient_RequestCompleted);
            settingsClient.Fetch();
        }

        void settingsClient_RequestCompleted(object sender, SimpleEventArgs<SettingsBase> e)
        {
            _settings.Merge(e.Result);
            this.player.MediaElement.SmoothStreamingSource = new Uri(_settings.VideoSource);
        }
    }
}
